package bot;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.CyclicBarrier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class Exe {
	public static final int legsC=3;
	protected static final Logger LOCAL_LOG = LogManager
			.getLogger(LogManager.ROOT_LOGGER_NAME);
	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
			
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				LOCAL_LOG.fatal(t.getName().intern()+"_"+e.getMessage(),e);
			}
		});
		System.out.println("RoBoT start");
		CyclicBarrier barrier=new CyclicBarrier(legsC);
		Leg[] legs=new Leg[legsC-1];
		for(int i=0;i<legs.length;i++)
			legs[i]=new Leg("LEG"+i,barrier);
		Head head=new Head(barrier,legs);
		LOCAL_LOG.info("RoBoT start");
		for(Leg leg:legs)
			leg.start();
		head.start();
		try {
			head.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LOCAL_LOG.info("RoBoT dead");
		LOCAL_LOG.exit();
	}

}
